using System;
using System.Collections.Generic;
using Scaffolding.Generator;

namespace Scaffolding.Exporter
{
    public class FileTokenReplacer : IFileTokenReplacer
    {
        private readonly IFileSystem _fileSystem;
        private Dictionary<string, string> _dictionary;

        public FileTokenReplacer(IFileSystem fileSystem)
        {
            _fileSystem = fileSystem;
        }

        public void SetTokens(Dictionary<string, string> dictionary)
        {
            _dictionary = dictionary;
        }

        public void Replace(string file)
        {
            string filedata = _fileSystem.ReadFile(file);

            foreach (KeyValuePair<string, string> pair in _dictionary)
            {

                filedata = TokenInserter.WordReplace(filedata,pair.Key,pair.Value);
            }

            _fileSystem.WriteFile(file,filedata);
        }
    }
}